package com.cf.crud.entity;

import com.cf.code.core.CField;
import com.cf.order.Ordered;
import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.Objects;

/**
 * cf-game-BaseEntity
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/3/1 18:13
 */
@MappedSuperclass
public abstract class BaseEntity implements Ordered, Serializable {

    @Id
    @CField(lab = "ID", search = true, order = 0, disable = true)
    public long id;

    //排序值
    @Column(name = "od")
    @CField(lab = "排序", type = "number")
    protected int od;

    @JsonIgnore
    @Column(name = "del")
    protected boolean del = false;

    public boolean getDel() {
        return del;
    }

    public void setDel(boolean del) {
        this.del = del;
    }

    public int getOd() {
        return od;
    }

    public void setOd(int od) {
        this.od = od;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof BaseEntity)) return false;
        BaseEntity that = (BaseEntity) o;
        return getId() == that.getId() &&
                getOd() == that.getOd() &&
                getDel() == that.getDel();
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId(), getOd(), getDel());
    }

    @Override
    public int getOrder() {
        return od;
    }

}
